package ms;
import robocode.*;
import java.awt.Color;

/**
 * ColonelReb - a robot by Matt Stine
 */
public class ColonelReb extends AdvancedRobot {

    public void run() {
        setColors(Color.blue,Color.red,Color.white);
        while (true) {
            turnGunLeft(360);
        }
    }

    public void onScannedRobot(ScannedRobotEvent e) {
        turnRadarLeft(getRadarTurnRemaining());
        setAhead(Math.sin(getTime() / 12) * Math.cos(getTime() / 7) * 1000 * Math.random());
        targetScannedRobot(e);
        fireWithRandomPower();
    }

    private void targetScannedRobot(ScannedRobotEvent e) {
        double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
        setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()));
    }

    private void fireWithRandomPower() {
        long firepower = Math.round(Math.random() * 3);
        if (firepower == 0) {
            firepower = 1;
        }
        fire(firepower);
    }

    public void onHitByBullet(HitByBulletEvent e) {
        turnRight(e.getBearing() + 90);
    }

    public void onHitRobot(HitRobotEvent e) {
        turnRight(e.getBearing() + 90);
    }

    public void onHitWall(HitWallEvent e) {
        turnLeft(e.getBearing() + 180);
        ahead(400);
    }
}